package cn.hj.springboot_mybatis.controller;

import cn.hj.springboot_mybatis.mapper.PersonMapper;
import cn.hj.springboot_mybatis.pojo.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class MyController {

    @Autowired
    PersonMapper personMapper;
    @GetMapping("/person/{id}")
    public String findPerson(@PathVariable("id") Integer id){
        Person onePerson = personMapper.findOnePerson(id);
        return onePerson.toString();
    }

    @GetMapping("/getAll")
    public String getAll(){
        List<Person> allPerson = personMapper.getAllPerson();
        return allPerson.toString();
    }


    @GetMapping("/insert")
    public String insertPerson(Person p){

        int i = personMapper.insertPerson(p);
        return p.toString();

    }

    @GetMapping("/delete/{id}")
    public String deletePerson(@PathVariable("id") Integer id){

        int i = personMapper.deletePerson(id);
        return "delete";

    }


    @GetMapping("/update")
    public String updatePerson(Person p){

        int i = personMapper.updatePerson(p);
        return p.toString();

    }

}
